package com.laxcen.basiclib.core.task.core.thread;

import android.text.TextUtils;

/**
 * 单个线程池的处理类
 */
class ThreadPoolHandler {
    private static final String TAG = "ThreadPool";
    private IExecutorService mExecutorService;

    ThreadPoolHandler(int coreSize, String groupName, int priority) {
        mExecutorService = new ThreadPool(coreSize, groupName, priority);
    }

    public IExecutorService getExecutorService() {
        return mExecutorService;
    }

    public static Builder newBuilder(int coreSize) {
        return new Builder(coreSize);
    }

    public static class Builder {
        private final int coreSize;
        private String threadName;
        private int priority;

        Builder(int coreSize) {
            if (coreSize <= 0) {
                coreSize = 1;
            }
            this.coreSize = coreSize;
        }

        Builder groupName(String groupName) {
            if (TextUtils.isEmpty(groupName)) {
                groupName = TAG;
            }
            this.threadName = groupName;
            return this;
        }

        Builder priority(int priority) {
            this.priority = priority;
            return this;
        }

        ThreadPoolHandler builder() {
            ThreadPoolHandler handler = new ThreadPoolHandler(coreSize, threadName, priority);
            return handler;
        }
    }
}
